using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Globalization;
using System.Windows.Forms;

namespace GDFlacTools.Controls.Progress
{
	#region Enum
	//#####
	public enum ProgressCaptionMode
	{
		None,
		Percent,
		Value,
		Custom
	}
	//#####
	public enum ProgressFloodStyle
	{
		Standard,
		Horizontal
	}
	//#####
	public enum ProgressBarEdge
	{
		None,
		Rectangle,
		Rounded
	}
	//#####
	public enum ProgressBarDirection
	{
		Horizontal,
		Vertical
	}
	//#####
	public enum ProgressStyle
	{
		Dashed,
		Solid
	}
	//#####
	#endregion

	[ToolboxBitmapAttribute(typeof(ProgressBar),"ExDotNet.ico") ]
	public class ProgressBar : UserControl
	{
#pragma warning disable 649
		private readonly Container _components;
#pragma warning restore 649

		#region Direction
		//#####
		private bool _mBoolInvert;
		[Description("Invert the progress direction")]
		[Category("_Orientation")]
		[Browsable(true)]
		public bool Invert
		{
			get
			{
				return _mBoolInvert;
			}
			set
			{
				_mBoolInvert = value;
				Invalidate();
			}
		}
		//#####
		private ProgressBarDirection _mDirection = ProgressBarDirection.Horizontal;
		[Description("Set the progress control horizontal or vertical")]
		[Category("_Orientation")]
		[Browsable(true)]
		public ProgressBarDirection Orientation
		{
			get
			{
				return _mDirection;
			}
			set
			{
				_mDirection = value;
				Invalidate();
			}
		}
		#endregion

		#region Edge
		//#####
		private ProgressBarEdge _mEdge = ProgressBarEdge.Rounded;
		[Description("Set the edge of the control")]
		[Category("_Edge")]
		[Browsable(true)]
		public ProgressBarEdge Edge
		{
			get
			{
				return _mEdge;
			}
			set
			{
				_mEdge = value;
				Invalidate();
			}
		}
		//#####
		private Color _mEdgeColor = Color.FromKnownColor( KnownColor.Gray );
		[Description("Set the edge color")]
		[Category("_Edge")]
		[Browsable(true)]
		public Color EdgeColor
		{
			get
			{
				return _mEdgeColor;
			}
			set
			{
				_mEdgeColor = value;
				Invalidate();
			}
		}
		//#####
		private Color _mEdgeLightColor = Color.FromKnownColor( KnownColor.LightGray );
		[Description("Set the edge light color")]
		[Category("_Edge")]
		[Browsable(true)]
		public Color EdgeLightColor
		{
			get
			{
				return _mEdgeLightColor;
			}
			set
			{
				_mEdgeLightColor = value;
				Invalidate();
			}
		}
		//#####
		private int _mEdgeWidth = 1;
		[Description("Set the edge width")]
		[Category("_Edge")]
		[Browsable(true)]
		public int EdgeWidth
		{
			get
			{
				return _mEdgeWidth;
			}
			set
			{
				_mEdgeWidth = value;
				if( _mEdgeWidth < 0 ) _mEdgeWidth = 0;
				if( _mEdgeWidth > Int16.MaxValue ) _mEdgeWidth = Int16.MaxValue;
				Invalidate();
			}
		}
		//#####
		#endregion

		#region Progress
		//#####
		private ProgressFloodStyle _mFloodStyle = ProgressFloodStyle.Standard;
		[Description("Set the floodstyle. Standard draws a standard xp-themed progressbar, and with Horizontal you can create a horizontal flood bar (for the best effect, set FloodPercentage to 1.0.")]
		[Category("_Progress")]
		[Browsable(true)]
		public ProgressFloodStyle FloodStyle
		{
			get
			{
				return _mFloodStyle;
			}
			set
			{
				_mFloodStyle = value;
				Invalidate();
			}
		}
		//#####
		private float _mFloatBarFlood = 0.20f;
		[Description("Set the percentage of the flood color, a value between 0.0 and 1.0.")]
		[Category("_Progress")]
		[Browsable(true)]
		public float FloodPercentage
		{
			get
			{
				return _mFloatBarFlood;
			}
			set
			{
				_mFloatBarFlood = value;
				if( _mFloatBarFlood < 0.0f ) _mFloatBarFlood = 0.0f;
				if( _mFloatBarFlood > 1.0f ) _mFloatBarFlood = 1.0f;
				Invalidate();
			}
		}
		//#####
		private int _mIntBarOffset = 1;
		[Description("Set the offset for the left, top, right and bottom")]
		[Category("_Progress")]
		[Browsable(true)]
		public int BarOffset
		{
			get
			{
				return _mIntBarOffset;
			}
			set
			{
				_mIntBarOffset = value;
				if( _mIntBarOffset < 0 ) _mIntBarOffset = 0;
				if( _mIntBarOffset > Int16.MaxValue ) _mIntBarOffset = Int16.MaxValue;
				Invalidate();
			}
		}
		//#####
		private int _mIntDashWidth = 5;
		[Description("Set the width of a dash if Dashed mode")]
		[Category("_Progress")]
		[Browsable(true)]
		public int DashWidth
		{
			get
			{
				return _mIntDashWidth;
			}
			set
			{
				_mIntDashWidth = value;
				if( _mIntDashWidth < 0 ) _mIntDashWidth = 0;
				if( _mIntDashWidth > Int16.MaxValue ) _mIntDashWidth = Int16.MaxValue;
				Invalidate();
			}
		}
		//#####
		private int _mIntDashSpace = 2;
		[Description("Set the space between every dash if Dashed mode")]
		[Category("_Progress")]
		[Browsable(true)]
		public int DashSpace
		{
			get
			{
				return _mIntDashSpace;
			}
			set
			{
				_mIntDashSpace = value;
				if( _mIntDashSpace < 0 ) _mIntDashSpace = 0;
				if( _mIntDashSpace > Int16.MaxValue ) _mIntDashSpace = Int16.MaxValue;
				Invalidate();
			}
		}
		//#####
		private ProgressStyle _mStyle = ProgressStyle.Dashed;
		[Description("Set progressbar style")]
		[Category("_Progress")]
		[Browsable(true)]
		public ProgressStyle ProgressBarStyle
		{
			get
			{
				return _mStyle;
			}
			set
			{
				_mStyle = value;
				Invalidate();
			}
		}
		//#####
		private Color _mColor1 = Color.FromArgb( 0 , 255 , 0 );
		[Description("Set the main color")]
		[Category("_Progress")]
		[Browsable(true)]
		public Color MainColor
		{
			get
			{
				return _mColor1;
			}
			set
			{
				_mColor1 = value;
				Invalidate();
			}
		}
		//#####
		private Color _mColor2 = Color.FromKnownColor( KnownColor.White );
		[Description("Set the second color")]
		[Category("_Progress")]
		[Browsable(true)]
		public Color SecondColor
		{
			get
			{
				return _mColor2;
			}
			set
			{
				_mColor2 = value;
				Invalidate();
			}
		}
		//#####
		private Color _mColorBack = Color.FromKnownColor( KnownColor.White );
		[Description("Set the background color")]
		[Category("_Progress")]
		[Browsable(true)]
		public Color ProgressBackColor
		{
			get
			{
				return _mColorBack;
			}
			set
			{
				_mColorBack = value;
				Invalidate();
			}
		}
		//#####
		#endregion

		#region Properties
		private int _mIntMinimum;
		[Description("Set the minimum value of this progress control")]
		[Category("Properties")]
		[Browsable(true)]
		public int Minimum
		{
			get
			{
				return _mIntMinimum;
			}
			set
			{
				if( value < _mIntMaximum ) _mIntMinimum = value;
				Invalidate();
			}
		}
		private int _mIntMaximum = 100;
		[Description("Set the maximum value of this progress control")]
		[Category("Properties")]
		[Browsable(true)]
		public int Maximum
		{
			get
			{
				return _mIntMaximum;
			}
			set
			{
				if( value > _mIntMinimum ) _mIntMaximum = value;
				Invalidate();
			}
		}
		private int _mIntValue = 33;
		[Description("Set the current value of this progress control")]
		[Category("Properties")]
		[Browsable(true)]
		public int Value
		{
			get
			{
				return _mIntValue;
			}
			set
			{
				_mIntValue = value;
				if( _mIntValue < _mIntMinimum ) _mIntValue = _mIntMinimum;
				if( _mIntValue > _mIntMaximum ) _mIntValue = _mIntMaximum;
				Invalidate();
			}
		}
		private int _mIntStep = 1;
		[Description("Set the step value")]
		[Category("Properties")]
		[Browsable(true)]
		public int Step
		{
			get
			{
				return _mIntStep;
			}
			set
			{
				_mIntStep = value;
				Invalidate();
			}
		}
		#endregion

		#region Constructor
		public ProgressBar()
		{
			InitializeComponent();

			SetStyle( ControlStyles.UserPaint , true );
			SetStyle( ControlStyles.AllPaintingInWmPaint , true );
			SetStyle( ControlStyles.DoubleBuffer , true );
		}
		#endregion

		#region Caption
		[Description("Change the font")]
		[Category("_Caption")]
		[Browsable(true)]
		public override Font Font
		{
			get
			{
				return base.Font;
			}
			set
			{
				base.Font = value;
				Invalidate();
			}
		}
		//#####
		private bool _mBoolShadow = true;
		[Description("Enable/Disable shadow")]
		[Category("_Caption")]
		[Browsable(true)]
		public bool Shadow
		{
			get
			{
				return _mBoolShadow;
			}
			set
			{
				_mBoolShadow = value;
				Invalidate();
			}
		}
		//#####
		private int _mIntShadowOffset = 1;
		[Description("Set shadow offset")]
		[Category("_Caption")]
		[Browsable(true)]
		public int ShadowOffset
		{
			get
			{
				return _mIntShadowOffset;
			}
			set
			{
				_mIntShadowOffset = value;
				Invalidate();
			}
		}
		//#####
		private bool _mBoolAntialias = true;
		[Description("Enable/Disable antialiasing")]
		[Category("_Caption")]
		[Browsable(true)]
		public bool TextAntialias
		{
			get
			{
				return _mBoolAntialias;
			}
			set
			{
				_mBoolAntialias = value;
				Invalidate();
			}
		}
		//#####
		private Color _mColorShadow = Color.FromKnownColor( KnownColor.White );
		[Description("Set the caption shadow color.")]
		[Category("_Caption")]
		[Browsable(true)]
		public Color CaptionShadowColor
		{
			get
			{
				return _mColorShadow;
			}
			set
			{
				_mColorShadow = value;
				Invalidate();
			}
		}
		//#####
		private Color _mColorCaption = Color.FromKnownColor( KnownColor.Black );
		[Description("Set the caption color.")]
		[Category("_Caption")]
		[Browsable(true)]
		public Color CaptionColor
		{
			get
			{
				return _mColorCaption;
			}
			set
			{
				_mColorCaption = value;
				Invalidate();
			}
		}
		//#####
		private ProgressCaptionMode _mCaptionMode = ProgressCaptionMode.Percent;
		[Description("Set the caption mode.")]
		[Category("_Caption")]
		[Browsable(true)]
		public ProgressCaptionMode CaptionMode
		{
			get
			{
				return _mCaptionMode;
			}
			set
			{
				_mCaptionMode = value;
				Invalidate();
			}
		}
		//#####
		private String _mStrCaption = "Progress";
		[Description("Set the caption.")]
		[Category("_Caption")]
		[Browsable(true)]
		public String Caption
		{
			get
			{
				return _mStrCaption;
			}
			set
			{
				_mStrCaption = value;
				Invalidate();
			}
		}
		//#####
		#endregion

		#region Custom
		//#####
		private bool _mBoolChangeByMouse;
		[Description("Allows the user to change the value by clicking the mouse")]
		[Category("_Custom")]
		[Browsable(true)]
		public bool ChangeByMouse
		{
			get
			{
				return _mBoolChangeByMouse;
			}
			set
			{
				_mBoolChangeByMouse = value;
				Invalidate();
			}
		}
		#endregion

		#region GetCustomCaption
		private String GetCustomCaption( String caption )
		{
			float floatPercentage = ( ( _mIntValue - _mIntMinimum ) / (float)( _mIntMaximum - _mIntMinimum ) ) * 100.0f;

            String toReturn = caption.Replace("<VALUE>", _mIntValue.ToString(CultureInfo.InvariantCulture));
            toReturn = toReturn.Replace("<PERCENTAGE>", floatPercentage.ToString(CultureInfo.InvariantCulture));

			return toReturn;
		}
		#endregion

		#region User Methods
		public void PerformStep()
		{
			_mIntValue += _mIntStep;
			if( _mIntValue < _mIntMinimum ) _mIntValue = _mIntMinimum;
			if( _mIntValue > _mIntMaximum ) _mIntValue = _mIntMaximum;
		}

		public void Increment( int val )
		{
			_mIntValue += val;
			if( _mIntValue < _mIntMinimum ) _mIntValue = _mIntMinimum;
			if( _mIntValue > _mIntMaximum ) _mIntValue = _mIntMaximum;
		}
		#endregion

		#region Overrides
		protected override void OnPaint(PaintEventArgs e)
		{
			#region OnPaint - Draw Background
			var brsh = new SolidBrush( _mColorBack );
			e.Graphics.FillRectangle( brsh , 0 , 0 , Width , Height );
			#endregion

			#region OnPaint - Draw ProgressBar
			switch( _mDirection )
			{
				#region Horizontal
				case ProgressBarDirection.Horizontal:
				{
					float floatProgressHeight = (Height - _mEdgeWidth*2 - _mIntBarOffset*2);
					float floatProgressTotalWidth = Width - _mEdgeWidth*2 - _mIntBarOffset*2;
					float floatProgressDrawWidth = floatProgressTotalWidth / ( _mIntMaximum - _mIntMinimum ) * ( _mIntValue - _mIntMinimum );

					var intNumberOfDashes = (int)( floatProgressDrawWidth / ( _mIntDashWidth + _mIntDashSpace ) );
					var intTotalDashes = (int)( floatProgressTotalWidth / ( _mIntDashWidth + _mIntDashSpace ) );

					var rectBar2 = new Rectangle(_mEdgeWidth + _mIntBarOffset,_mEdgeWidth + _mIntBarOffset, (int)floatProgressTotalWidth, (int)floatProgressHeight);
					Rectangle rectBar;
					if( _mBoolInvert )
					{
						rectBar = new Rectangle(
								  _mEdgeWidth + _mIntBarOffset + (int)( floatProgressTotalWidth - floatProgressDrawWidth )
								, _mEdgeWidth + _mIntBarOffset
								, (int)floatProgressDrawWidth
								, (int)floatProgressHeight);
					}
					else
					{
						rectBar = new Rectangle(
								  _mEdgeWidth + _mIntBarOffset
								, _mEdgeWidth + _mIntBarOffset
								, (int)floatProgressDrawWidth
								, (int)floatProgressHeight);
					}

					var brshBar = new LinearGradientBrush( rectBar2 , _mColor2 , _mColor1 , (_mFloodStyle == ProgressFloodStyle.Standard) ? 90.0f : 0.0f );
					float[] factors = {0.0f, 1.0f, 1.0f, 0.0f}; 
					float[] positions = {0.0f, _mFloatBarFlood, 1.0f - _mFloatBarFlood, 1.0f};

				    var blend = new Blend {Factors = factors, Positions = positions};

				    brshBar.Blend = blend;

					switch( _mStyle )
					{
						case ProgressStyle.Solid:
						{
							e.Graphics.FillRectangle( brshBar , rectBar);
							break;
						}
						case ProgressStyle.Dashed:
						{
							if( _mBoolInvert )
							{
								if( intNumberOfDashes == 0 ) intNumberOfDashes = -1;
								for( int i=0 ; i<intNumberOfDashes+1 ; i++ )
								{
									int j = i + (intTotalDashes - intNumberOfDashes);
									e.Graphics.FillRectangle( brshBar , new Rectangle( _mEdgeWidth + _mIntBarOffset + ( j*(_mIntDashWidth+_mIntDashSpace) ) , _mEdgeWidth + _mIntBarOffset , _mIntDashWidth , (int)floatProgressHeight ) );
								}
							}
							else
							{
								if( intNumberOfDashes == 0 ) intNumberOfDashes = -1;
								for( int i=0 ; i<intNumberOfDashes+1 ; i++ )
								{
									e.Graphics.FillRectangle( brshBar , new Rectangle( _mEdgeWidth + _mIntBarOffset + ( i*(_mIntDashWidth+_mIntDashSpace) ) , _mEdgeWidth + _mIntBarOffset , _mIntDashWidth , (int)floatProgressHeight ) );
								}
							}
							break;
						}
					}
					brshBar.Dispose();
					break;
				}
				#endregion
				#region Vertical
				case ProgressBarDirection.Vertical:
				{
					float floatProgressWidth = (Width - _mEdgeWidth*2 - _mIntBarOffset*2);
					float floatProgressTotalHeight = Height - _mEdgeWidth*2 - _mIntBarOffset*2;
					float floatProgressDrawHeight = floatProgressTotalHeight / ( _mIntMaximum - _mIntMinimum ) * ( _mIntValue - _mIntMinimum );

					var intNumberOfDashes = (int)( floatProgressDrawHeight / ( _mIntDashWidth + _mIntDashSpace ) );
					var intTotalDashes = (int)( floatProgressTotalHeight / ( _mIntDashWidth + _mIntDashSpace ) );

					var rectBar2 = new Rectangle(_mEdgeWidth + _mIntBarOffset,_mEdgeWidth + _mIntBarOffset, (int)floatProgressWidth , (int)floatProgressTotalHeight );
					Rectangle rectBar;
					if( _mBoolInvert )
					{
						rectBar = new Rectangle(
							  _mEdgeWidth + _mIntBarOffset
							, _mEdgeWidth + _mIntBarOffset + (int)( floatProgressTotalHeight - floatProgressDrawHeight )
							, (int)floatProgressWidth
							, (int)floatProgressDrawHeight);
					}
					else
					{
						rectBar = new Rectangle(
							  _mEdgeWidth + _mIntBarOffset
							, _mEdgeWidth + _mIntBarOffset
							, (int)floatProgressWidth 
							, (int)floatProgressDrawHeight);
					}

					var brshBar = new LinearGradientBrush( rectBar2 , _mColor2 , _mColor1 , (_mFloodStyle == ProgressFloodStyle.Standard) ? 0.0f : 90.0f );
					float[] factors = {0.0f, 1.0f, 1.0f, 0.0f}; 
					float[] positions = {0.0f, _mFloatBarFlood, 1.0f - _mFloatBarFlood, 1.0f};

				    var blend = new Blend {Factors = factors, Positions = positions};

				    brshBar.Blend = blend;

					switch( _mStyle )
					{
						case ProgressStyle.Solid:
						{
							e.Graphics.FillRectangle( brshBar , rectBar);
							break;
						}
						case ProgressStyle.Dashed:
						{
							if( _mBoolInvert )
							{
								if( intNumberOfDashes == 0 ) intNumberOfDashes = -1;
								for( int i=0 ; i<intNumberOfDashes+1 ; i++ )
								{
									int j = i + (intTotalDashes - intNumberOfDashes);
									e.Graphics.FillRectangle( brshBar , new Rectangle( _mEdgeWidth + _mIntBarOffset , _mEdgeWidth + _mIntBarOffset + ( j*(_mIntDashWidth+_mIntDashSpace) ) , (int)floatProgressWidth , _mIntDashWidth ) );
								}
							}
							else
							{
								if( intNumberOfDashes == 0 ) intNumberOfDashes = -1;
								for( int i=0 ; i<intNumberOfDashes+1 ; i++ )
								{
									e.Graphics.FillRectangle( brshBar , new Rectangle( _mEdgeWidth + _mIntBarOffset , _mEdgeWidth + _mIntBarOffset + ( i*(_mIntDashWidth+_mIntDashSpace) ) , (int)floatProgressWidth , _mIntDashWidth ) );
								}
							}
							break;
						}
					}
					brshBar.Dispose();
					break;
				}
				#endregion
			}
			#endregion

			#region OnPaint - Draw Edge
			switch( _mEdge )
			{
				case ProgressBarEdge.Rectangle:
				{
					var pen = new Pen( _mEdgeColor );
					var pen3 = new Pen( _mEdgeLightColor );
					for( int i=0 ; i<_mEdgeWidth ; i++ )
					{
						e.Graphics.DrawRectangle( pen , 0+i , 0+i , Width-1-i*2 , Height-1-i*2 );
					}
					e.Graphics.DrawLine( pen3 , _mEdgeWidth , _mEdgeWidth , Width-1-_mEdgeWidth , _mEdgeWidth );
					e.Graphics.DrawLine( pen3 , _mEdgeWidth , _mEdgeWidth , _mEdgeWidth , Height-1-_mEdgeWidth );
					break;
				}
				case ProgressBarEdge.Rounded:
				{
					Pen pen = new Pen( _mEdgeColor );
					Pen pen2 = new Pen( this.BackColor );
					Pen pen3 = new Pen( _mEdgeLightColor );
					for( int i=0 ; i<_mEdgeWidth ; i++ )
					{
						e.Graphics.DrawRectangle( pen , 0+i , 0+i , Width-1-i*2 , Height-1-i*2 );
					}
					e.Graphics.DrawLine( pen2 , 0 , 0 , 1 , 0 );
					e.Graphics.DrawLine( pen2 , 0 , 0 , 0 , 1 );
					e.Graphics.DrawLine( pen2 , 0 , Height-1 , 1 , Height-1 );
					e.Graphics.DrawLine( pen2 , 0 , Height-1 , 0 , Height-2 );
					e.Graphics.DrawLine( pen2 , Width-2 , 0 , Width-1 , 0 );
					e.Graphics.DrawLine( pen2 , Width-1 , 0 , Width-1 , 1 );
					e.Graphics.DrawLine( pen2 , Width-2 , Height-1 , Width-1 , Height-1 );
					e.Graphics.DrawLine( pen2 , Width-1 , Height-2 , Width-1 , Height-1 );

					e.Graphics.FillRectangle( new SolidBrush( _mEdgeColor ) , _mEdgeWidth , _mEdgeWidth , 1 , 1 );
					e.Graphics.FillRectangle( new SolidBrush( _mEdgeColor ) , _mEdgeWidth , Height-1-_mEdgeWidth , 1 , 1 );
					e.Graphics.FillRectangle( new SolidBrush( _mEdgeColor ) , Width-1-_mEdgeWidth , _mEdgeWidth , 1 , 1 );
					e.Graphics.FillRectangle( new SolidBrush( _mEdgeColor ) , Width-1-_mEdgeWidth , Height-1-_mEdgeWidth , 1 , 1 );

					e.Graphics.DrawLine( pen3 , _mEdgeWidth+1 , _mEdgeWidth , Width-2-_mEdgeWidth , _mEdgeWidth );
					e.Graphics.DrawLine( pen3 , _mEdgeWidth , _mEdgeWidth+1 , _mEdgeWidth , Height-2-_mEdgeWidth );

					break;
				}
			}
			#endregion

			#region OnPaint - Draw Caption
			if( _mBoolAntialias ) e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
			StringFormat format = new StringFormat();
			format.LineAlignment = StringAlignment.Center;
			format.Alignment = StringAlignment.Center;
			format.Trimming = StringTrimming.EllipsisCharacter;
			switch( _mCaptionMode )
			{
				case ProgressCaptionMode.Value:
				{
					if( _mBoolShadow )
					{
						e.Graphics.DrawString( _mIntValue.ToString() , this.Font , new SolidBrush( _mColorShadow ) , new Rectangle( _mIntShadowOffset , _mIntShadowOffset , this.Width , this.Height ) , format );
					}
					e.Graphics.DrawString( _mIntValue.ToString() , this.Font , new SolidBrush( _mColorCaption ) , new Rectangle( 0 , 0 , this.Width , this.Height ) , format );
					break;
				}
				case ProgressCaptionMode.Percent:
				{
					float float_Percentage = ( (float) ( _mIntValue - _mIntMinimum ) / (float)( _mIntMaximum - _mIntMinimum ) ) * 100.0f;
					if( _mBoolShadow )
					{
						e.Graphics.DrawString( float_Percentage.ToString() + "%" , this.Font , new SolidBrush( _mColorShadow ) , new Rectangle( _mIntShadowOffset , _mIntShadowOffset , this.Width , this.Height ) , format );
					}
					e.Graphics.DrawString( float_Percentage.ToString() + "%" , this.Font , new SolidBrush( _mColorCaption ) , new Rectangle( 0 , 0 , this.Width , this.Height ) , format );
					break;
				}
				case ProgressCaptionMode.Custom:
				{
					if( _mBoolShadow )
					{
						e.Graphics.DrawString( GetCustomCaption( _mStrCaption ) , this.Font , new SolidBrush( _mColorShadow ) , new Rectangle( _mIntShadowOffset , _mIntShadowOffset , this.Width , this.Height ) , format );
					}
					e.Graphics.DrawString( GetCustomCaption( _mStrCaption ) , this.Font , new SolidBrush( _mColorCaption ) , new Rectangle( 0 , 0 , this.Width , this.Height ) , format );
					break;
				}
			}
			#endregion

			base.OnPaint (e);
		}

		protected override void OnResize(EventArgs e)
		{
			Invalidate();
			base.OnResize (e);
		}

		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(_components != null)
				{
					_components.Dispose();
				}
			}
			base.Dispose( disposing );
		}
		#endregion

		#region Component Designer generated code
		/// <summary> 
		/// Required method for Designer support - do not modify 
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			// 
			// ProgressBar
			// 
			this.Name = "ProgressBar";
			this.Size = new System.Drawing.Size(256, 24);
			this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.ProgressBar_MouseUp);
			this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.ProgressBar_MouseMove);
			this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.ProgressBar_MouseDown);

		}
		#endregion

		#region ChangeByMouse
		private void ProgressBar_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			/**/
		}

		private void ProgressBar_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			if( _mBoolChangeByMouse && e.Button == MouseButtons.Left )
			{
				if( _mDirection == ProgressBarDirection.Horizontal )
				{
					int int_ProgressWidth = this.Width - _mIntBarOffset*2 - _mEdgeWidth*2;
					int int_MousePos = e.X - _mIntBarOffset - _mEdgeWidth;

					float percentageClick = (float)int_MousePos / (float)int_ProgressWidth;

					int int_Range = _mIntMaximum - _mIntMinimum;
					int int_NewValue = (int)( (float)int_Range * percentageClick );
					if( _mBoolInvert ) int_NewValue = int_Range - int_NewValue;
					int_NewValue += _mIntMinimum;
					if( int_NewValue < _mIntMinimum ) int_NewValue = _mIntMinimum;
					if( int_NewValue > _mIntMaximum ) int_NewValue = _mIntMaximum;
					_mIntValue = int_NewValue;
				}
				else
				{
					int int_ProgressWidth = this.Height - _mIntBarOffset*2 - _mEdgeWidth*2;
					int int_MousePos = e.Y - _mIntBarOffset - _mEdgeWidth;

					float percentageClick = (float)int_MousePos / (float)int_ProgressWidth;

					int int_Range = _mIntMaximum - _mIntMinimum;
					int int_NewValue = (int)( (float)int_Range * percentageClick );
					if( _mBoolInvert ) int_NewValue = int_Range - int_NewValue;
					int_NewValue += _mIntMinimum;
					if( int_NewValue < _mIntMinimum ) int_NewValue = _mIntMinimum;
					if( int_NewValue > _mIntMaximum ) int_NewValue = _mIntMaximum;
					_mIntValue = int_NewValue;
				}
				Invalidate();
			}
		}

		private void ProgressBar_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			if( _mBoolChangeByMouse )
			{
				if( _mDirection == ProgressBarDirection.Horizontal )
				{
					int int_ProgressWidth = this.Width - _mIntBarOffset*2 - _mEdgeWidth*2;
					int int_MousePos = e.X - _mIntBarOffset - _mEdgeWidth;

					float percentageClick = (float)int_MousePos / (float)int_ProgressWidth;

					int int_Range = _mIntMaximum - _mIntMinimum;
					int int_NewValue = (int)( (float)int_Range * percentageClick );
					if( _mBoolInvert ) int_NewValue = int_Range - int_NewValue;
					int_NewValue += _mIntMinimum;
					if( int_NewValue < _mIntMinimum ) int_NewValue = _mIntMinimum;
					if( int_NewValue > _mIntMaximum ) int_NewValue = _mIntMaximum;
					_mIntValue = int_NewValue;
				}
				else
				{
					int int_ProgressWidth = this.Height - _mIntBarOffset*2 - _mEdgeWidth*2;
					int int_MousePos = e.Y - _mIntBarOffset - _mEdgeWidth;

					float percentageClick = (float)int_MousePos / (float)int_ProgressWidth;

					int int_Range = _mIntMaximum - _mIntMinimum;
					int int_NewValue = (int)( (float)int_Range * percentageClick );
					if( _mBoolInvert ) int_NewValue = int_Range - int_NewValue;
					int_NewValue += _mIntMinimum;
					if( int_NewValue < _mIntMinimum ) int_NewValue = _mIntMinimum;
					if( int_NewValue > _mIntMaximum ) int_NewValue = _mIntMaximum;
					_mIntValue = int_NewValue;
				}
				Invalidate();
			}
		}
		#endregion
	}
}
